/*
 * Copyright (c) $today.year-Now http://www.zxpnet.com All rights reserved.
 */

package com.zxp.springboot.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * 依照org.springframework.boot.context.event.EventPublishingRunListener 写法
 * @desc:
 * @author: shollin
 * @date: 2021/6/19/019 22:36
 */

@Slf4j
public class MySpringApplicationRunListener implements SpringApplicationRunListener {

    private final SpringApplication application;
    private final String[] args;

    public MySpringApplicationRunListener(SpringApplication application, String[] args) {
        this.application = application;
        this.args = args;
    }

    @Override
    public void starting(ConfigurableBootstrapContext bootstrapContext) {
        log.debug("MySpringApplicationRunListener starting...");
        SpringApplicationRunListener.super.starting(bootstrapContext);
    }


    @Override
    public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext, ConfigurableEnvironment environment) {
        log.debug("MySpringApplicationRunListener environmentPrepared...");
        SpringApplicationRunListener.super.environmentPrepared(bootstrapContext, environment);
    }


    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
        log.debug("MySpringApplicationRunListener contextPrepared...");
        SpringApplicationRunListener.super.contextPrepared(context);
    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
        log.debug("MySpringApplicationRunListener contextLoaded...");
        SpringApplicationRunListener.super.contextLoaded(context);
    }

    @Override
    public void started(ConfigurableApplicationContext context) {
        log.debug("MySpringApplicationRunListener started...");

        //DataSourceProperties dataSourceProperties = context.getBean(DataSourceProperties.class);
        //if(dataSourceProperties!=null){
//            log.info("--------------"+dataSourceProperties.getDriverClassName());
//        }

        SpringApplicationRunListener.super.started(context);
    }

    @Override
    public void running(ConfigurableApplicationContext context) {
        SpringApplicationRunListener.super.running(context);
    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
        SpringApplicationRunListener.super.failed(context, exception);
    }
}
